//
//  SubmitPay.m
//  Courses
//
//  Created by YiXuePxh on 15/4/21.
//  Copyright (c) 2015年 boyibang. All rights reserved.
//

#import "SubmitPay.h"

@implementation SubmitPay
//-(id)initWithResponse:(Response* )response{
//    self.result = response.result;
//    self.msg = response.msg;
//    return self;
//}
- (id)initWithJsonDict:(NSDictionary* )jsonDict{
    self.orderId = jsonDict[@"orderId"];
    self.orderNo = jsonDict[@"orderNo"];
    return self;
}


+(SubmitPay* )getOrderWithSubmitOrder:(SubmitOrder* )submitOrder{
    SubmitPay* pay;
    Request* request = [Request requestWithName:@"submit_order"];
    request.body[@"sourceId"] = submitOrder.sourceId;
    request.body[@"deviceNo"] = submitOrder.deviceNo;
    request.body[@"version"] = submitOrder.version;
    request.body[@"agencyId"] = submitOrder.agencyId;
    request.body[@"userId"] = submitOrder.userId;
    request.body[@"classId"] = submitOrder.classId;
    request.body[@"courseId"] = submitOrder.courseId;
    request.body[@"teacherId"] = submitOrder.teacherId;
    request.body[@"orderAmount"] = submitOrder.orderAmount;
    request.body[@"realAmount"] = submitOrder.realAmount;
    request.body[@"discount"] = submitOrder.discount;
    request.body[@"mobile"] = submitOrder.mobile;
    request.body[@"userName"] = submitOrder.userName;
    request.body[@"salesCode"] = submitOrder.salesCode;
    request.body[@"invoiceType"] = submitOrder.invoiceType;
    request.body[@"invoiceTitle"] = submitOrder.invoiceTitle;
    request.body[@"invoiceAddress"] = submitOrder.invoiceAddress;
    NSMutableArray* coupons = [[NSMutableArray alloc]init];
    NSMutableDictionary* couponDiction = [[NSMutableDictionary alloc]init];
    couponDiction[@"couponCode"] = submitOrder.coupons;
    [coupons addObject:couponDiction];
    request.body[@"coupons"] = coupons;
    Response* response = [request response];
    if (!response.result) {
        return pay;
    }
    if (response.result) {
        if ([response.content[@"order"] isKindOfClass:[NSDictionary class]]) {
            pay = [[SubmitPay alloc]initWithJsonDict:response.content[@"order"]];
        }
    }
    return pay;
}


@end
